from django.db import models


class Customer(models.Model):
    """
    用户表 Customer:
    用户名:user_name
    密码: password
    手机号: phone
    邮箱: email
    创建时间: create_time
    修改时间: update_time
    """
    user_name = models.CharField(max_length=200)
    password = models.CharField(max_length=200)
    phone = models.IntegerField()
    email = models.EmailField(max_length=200)
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.user_name


class CustomerAddress(models.Model):
    """
    用户地址表 CustomerAddress:
    用户ID: customer_id  外键Customer
    地址ID: address_id
    收货人姓名: consignee_name
    收货人手机号: consignee_phone
    收货人省份: consignee_province
    收货人城市: consignee_city
    收货人县/市: consignee_town
    收货人地址: consignee_address
    收货人邮政编码: consignee_postcode
    创建时间: create_time
    修改时间: update_time
    """
    customer_id = models.ForeignKey(Customer, on_delete=models.CASCADE)
    address_id = models.CharField(max_length=200)
    consignee_name = models.CharField(max_length=200)
    consignee_phone = models.IntegerField()
    consignee_province = models.CharField(max_length=200)
    consignee_city = models.CharField(max_length=200)
    consignee_town = models.CharField(max_length=200)
    consignee_address = models.CharField(max_length=200)
    consignee_postcode = models.CharField(max_length=200)
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.consignee_address


class Status(models.Model):
    """
    状态表
    """
    status = models.CharField(max_length=20)

    def __str__(self):
        return self.status


class CommodityKind(models.Model):
    """
    商品类别表 CommodityKind:
    类别id: kind_id
    商品类名: commodity_kind
    排序优先级: priority
    创建时间: create_time
    修改时间: update_time
    """
    kind_id = models.CharField(max_length=200)
    commodity_kind = models.CharField(max_length=200)
    priority = models.CharField(max_length=200)
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.commodity_kind


class CommodityKindTow(models.Model):
    """
    商品二级分类 CommodityKindTow:
    分类
    """
    pass


class CommodityImage(models.Model):
    """
    商品图片分类图片 CommodityImage
    图片id: image_id
    分类id: kind_id  外键 CommodityKind
    图片名: image_name
    网页地址: site_url
    图片大小: image_size
    图片状态: image_status  外键 Status
    图片路径: image_url
    排序优先级: priority
    创建时间: create_time
    修改时间: update_time
    """
    image_id = models.CharField(max_length=200)
    kind_id = models.ForeignKey(CommodityKind, on_delete=models.CASCADE)
    image_name = models.CharField(max_length=200)
    site_url = models.CharField(max_length=200)
    image_size = models.CharField(max_length=200)
    image_status = models.ForeignKey(Status, on_delete=models.CASCADE)
    image_url = models.ImageField(upload_to='image')
    priority = models.CharField(max_length=200)
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.image_name


class Commodity(models.Model):
    """
    商品表 Commodity :
    商品编码: commodity_id
    商品标题: commodity_title
    商品卖点: commodity_point
    商品价格: commodity_price
    库存数量: stock_number
    商品图片: commodity_image
    商品条码: commodity_code
    所属类目: commodity_kind  外键CommodityKind
    商品状态(上架, 下架, 删除): commodity_status   外键Status
    商品重量: commodity_kg
    创建时间: create_time
    修改时间: update_time
    """
    commodity_id = models.CharField(max_length=200)
    commodity_title = models.CharField(max_length=200)
    commodity_point = models.CharField(max_length=200)
    commodity_price = models.IntegerField(blank=True, null=True)
    commodity_number = models.IntegerField(blank=True, null=True)
    commodity_image = models.ForeignKey(CommodityImage, on_delete=models.CASCADE)
    commodity_code = models.IntegerField()
    commodity_kind = models.ForeignKey(CommodityKind, on_delete=models.CASCADE)
    commodity_status = models.ForeignKey(Status, on_delete=models.CASCADE)
    commodity_kg = models.CharField(max_length=200)
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.commodity_title


class CommodityDescribe(models.Model):
    """
    商品描述表 CommodityDescribe:
    商品id: commodity_id   外键Commodity
    商品描述: commodity_describe
    创建时间: create_time
    修改时间: update_time
    """
    commodity_id = models.ForeignKey(Commodity, on_delete=models.CASCADE)
    commodity_describe = models.CharField(max_length=200)
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.commodity_describe


class CommoditySize(models.Model):
    """
    商品规格表  CommoditySize:
    商品类目id commodity_kind_id   外键 CommodityKind
    参数: parameter
    创建时间: create_time
    修改时间: update_time
    """
    commodity_kind_id = models.ForeignKey(CommodityKind, on_delete=models.CASCADE)
    parameter = models.CharField(max_length=200)
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.parameter


class TypePay(models.Model):
    """
    支付类型
    """
    type_pay = models.CharField(max_length=200)

    def __str__(self):
        return self.type_pay


class Logistics(models.Model):
    """
    物流
    """
    logistics_name = models.CharField(max_length=200)

    def __str__(self):
        return self.logistics_name


class ReturnGoods(models.Model):
    """
    退货无忧
    """
    return_goods = models.CharField(max_length=200)


class Orders(models.Model):
    """
    订单表 Orders:
    订单id: order_id
    用户id: customer_id  外键 Customer
    收货地址id: address_id 外键 CustomerAddress
    实付金额: pay_money
    支付类型: type_pay 外键 TypePay
    邮费: postage
    订单状态: order_status 外键 Status
    物流名称: logistics_name  外键 Logistics
    物流单号: logistics_number
    退货无忧: return_goods  外键 ReturnGoods
    订单总重: orders_kg
    买家是否已经评价: is_evaluate 外键 Status
    交易关闭时间: close_time
    交易完成时间: finish_time
    付款时间: pay_time
    发货时间: send_time
    订单创建时间: create_time
    订单更新时间: update_time
    """
    order_id = models.CharField(max_length=200)
    customer_id = models.ForeignKey(Customer, on_delete=models.CASCADE)
    address_id = models.ForeignKey(CustomerAddress, on_delete=models.CASCADE)
    pay_money = models.CharField(max_length=20)
    type_pay = models.ForeignKey(TypePay, on_delete=models.CASCADE)
    postage = models.CharField(max_length=20)
    order_status = models.ForeignKey(Status, on_delete=models.CASCADE,related_name='order_status')
    logistics_name = models.ForeignKey(Logistics, on_delete=models.CASCADE)
    logistics_number = models.CharField(max_length=200)
    return_goods = models.ForeignKey(ReturnGoods, on_delete=models.CASCADE)
    orders_kg = models.CharField(max_length=20)
    is_evaluate = models.ForeignKey(Status, on_delete=models.CASCADE,related_name='is_evaluate')
    close_time = models.DateTimeField(auto_now_add=True)
    finish_time = models.DateTimeField(auto_now_add=True)
    pay_time = models.DateTimeField(auto_now_add=True)
    send_time = models.DateTimeField(auto_now_add=True)
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.order_id


class OrdersKind(models.Model):
    """
    订单类目表 OrdersKind :
    id: 自动生成
    商品id: commodity_id   外键Commodity
    订单id: order_id  外键 Orders
    购买数量: quantity
    商品标题: commodity_title  外键Commodity
    商品单价: commodity_price  外键Commodity
    商品总金额: commodity_amount
    商品图片: commodity_image  外键Commodity
    商品重量: commodity_kg  外键Commodity
    """
    commodity_id = models.ForeignKey(Commodity, on_delete=models.CASCADE,related_name='Commodity_id')
    order_id = models.ForeignKey(Orders, on_delete=models.CASCADE)
    quantity = models.CharField(max_length=200)
    commodity_title = models.ForeignKey(Commodity, on_delete=models.CASCADE,related_name='Commodity_title')
    commodity_price = models.ForeignKey(Commodity, on_delete=models.CASCADE,related_name='Commodity_price')
    commodity_amount = models.CharField(max_length=200)
    commodity_image = models.ForeignKey(CommodityImage, on_delete=models.CASCADE)
    commodity_kg = models.ForeignKey(Commodity, on_delete=models.CASCADE,related_name='Commodity_kg')


class WordKind(models.Model):
    """
    热词分类 WordKind:
    热词种类: word_kind
    """
    word_kind = models.CharField(max_length=200)


class HotWord(models.Model):
    """
    热门词 HotWord
    id :　自动生成
    分类: word_kind  外键 WordKind
    热词名称: word_name
    超链接: link
    热词状态: status  外键 Status
    创建时间: create_time
    修改时间: update_time
    """
    word_kind = models.ForeignKey(WordKind, on_delete=models.CASCADE)
    word_name = models.CharField(max_length=200)
    link = models.CharField(max_length=200)
    status = models.ForeignKey(Status, on_delete=models.CASCADE)
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)


class Advertising(models.Model):
    """
    首页轮播广告表 Advertising :
    id: 自动生成
    alt信息: alt_msg
    网址: site_url
    大图: big_img
    小图: small_img
    状态: status  外键  Status
    排序优先级: priority
    """
    alt_msg = models.CharField(max_length=200)
    site_url = models.CharField(max_length=200)
    big_img = models.ImageField(upload_to='big_img')
    small_img = models.ImageField(upload_to='small_img')
    status = models.ForeignKey(Status, on_delete=models.CASCADE)
    priority = models.CharField(max_length=20)




